/// <reference types="./env.d.ts" />

import { defineConfig, type ConfigEnv, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
// import postcssPxToViewport from 'postcss-px-to-viewport'
import { fileURLToPath, URL } from 'node:url'
// import path from 'path'
import vueJsx from '@vitejs/plugin-vue-jsx'
import topLevelAwait from 'vite-plugin-top-level-await'
import cesium from 'vite-plugin-cesium'

export default defineConfig((mode: ConfigEnv) => {
  const env = loadEnv(mode.mode, process.cwd())
  return {
    base: './',
    plugins: [vue(), vueJsx(), topLevelAwait(), cesium()],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    // css: {
    //   postcss: {
    //     plugins: [
    //       postcssPxToViewport({
    //         viewportWidth: 4368,
    //         unitPrecision: 2,
    //         viewportUnit: 'vw',
    //         // selectorBlackList: ['ignore', 'hairlines'], // 添加常用忽略类名
    //         minPixelValue: 2,
    //         mediaQuery: false,
    //         // exclude: [/node_modules/],
    //       }),
    //     ],
    //   },
    // },
    server: {
      port: 8013,
      proxy: {
        '/city': {
          target: env.VITE_APP_PROXY_TARGET,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/daping/, ''), // 修改rewrite规则
        },
        '/yztapi/cockpit': {
          target: env.VITE_APP_PROXY_TARGET,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/daping/, ''), // 修改rewrite规则
        },
      },
    },
  }
})
